<?php

namespace App\Services;

use App\Models\Department;
use Encore\Admin\Grid;

class BookSaleService
{
    public function gridColumn(Grid $grid, $role = 0): Grid
    {
        $grid->column('sn', '登记号');
        $grid->column('name', '名称')->filter('like');
        $grid->column('buyer', '受让方')->filter('like');
        $grid->column('sale_amount', '转化金额(万)');
        $grid->column('sale_type', '转化类型')->filter(select_sale_type_options());
        $grid->column('sale_date', '转化日期');
        $grid->column('department.name', '负责单位');
        $grid->column('user.name', '负责人');
        $grid->column('contact_person', '联系人');
        $grid->column('contact_mobile', '联系电话');
        $grid->disableActions();
        $grid->disableCreateButton();
        $grid->batchActions(function(Grid\Tools\BatchActions $actions)use($role){
            $actions->disableDelete();
        });
        $grid->filter(function(Grid\Filter $filter){
            $filter->disableIdFilter();
            $filter->column(1/2,function(Grid\Filter $filter){
                $filter->year('sale_date','转化年份');
            });
            $filter->column(1/2,function(Grid\Filter $filter){
                $filter->equal('department_id','负责单位')->select(Department::departmentOptions());
            });
        });
        $grid->fixHeader();
        return $grid;
    }

}
